package com.dyw.mybatispuls07generator.autoGenerator;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Collections;
import java.util.Locale;
import java.util.Scanner;

/**
 * @author Devil
 * @create 2022-01-23-14:20
 */
@SuppressWarnings("all")
public class Generator {

    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/my_db";
        String name = "root";
        String password = "devil";

        FastAutoGenerator.create(url,name,password)
                //全局配置
                .globalConfig((scanner,builder) ->
                        builder.author("Devil")
                                //输出目录
                                .outputDir("E:\\MyBatis\\mybatis-puls-07-generator"+"\\src\\main\\java")
                                //覆盖已生成的文件
                                .fileOverride()
                                //禁止打开输出目录: 默认true
                                .disableOpenDir()
                )
                //包配置
                .packageConfig((scanner,builder)->
                        builder.parent("com.dyw.mybatispuls07generator")
                                //自定义实体包名
                                .entity("entity")
                )
                //策略配置
                .strategyConfig((scanner,builder) ->
                        builder.addInclude("user")
                                //控制层配置
                                .controllerBuilder().enableRestStyle().enableHyphenStyle()
                                //服务层配置
                                .serviceBuilder()
                                    //去除服务接口的I前缀 %s表示实体类名:
                                    .formatServiceFileName("%sServcie")
                                //实体层配置
                                .entityBuilder()
                                .enableLombok()
                                //主键策略
                                .idType(IdType.AUTO)
                                //时间自动填充
//                                .addTableFills(new Column("gmt_create", FieldFill.INSERT))
//                                .addTableFills(new Column("gmt_modified", FieldFill.INSERT_UPDATE))
                                //乐观锁
                                .versionColumnName("version")
                                .versionPropertyName("version")
                                //逻辑删除
                                .logicDeleteColumnName("deleted")
                                .logicDeletePropertyName("deleted")
                ).templateEngine(new VelocityTemplateEngine()).execute();
    }
}
